#%%
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.dates as mdate
from matplotlib.pyplot import rcParams
from PIL import Image
import PIL
# natural population growth data
population = pd.read_csv('../../data/01-modified-data/cleaned-population-py.csv')
#normalize
population['Natural_growth_rate'] = (population['Natural_growth_rate']-np.mean(population['Natural_growth_rate']))/np.std(population['Natural_growth_rate'])
population['GDP'] = (population['GDP']-np.mean(population['GDP']))/np.std(population['GDP'])
population['Deaths'] = (population['Deaths']-np.mean(population['Deaths']))/np.std(population['Deaths'])
population['Births'] = (population['Births']-np.mean(population['Births']))/np.std(population['Births'])
population['Life expectancy'] = (population['Life expectancy']-np.mean(population['Life expectancy']))/np.std(population['Life expectancy'])
population['Disability'] = (population['Disability']-np.mean(population['Disability']))/np.std(population['Disability'])
population = population.drop(columns=['Unnamed: 0'])
population.head()
| Entity | Year | Natural_growth_rate | GDP | Deaths | Births | Life expectancy | Disability | |
|---|---|---|---|---|---|---|---|---|
| 0 | Afghanistan | 2002 | 1.989026 | -0.816805 | -0.087527 | -0.050382 | -1.221520 | 1.485177 |
| 1 | Afghanistan | 2003 | 1.970820 | -0.814436 | -0.084880 | -0.042510 | -1.170627 | 1.358566 |
| 2 | Afghanistan | 2004 | 1.916201 | -0.816265 | -0.084105 | -0.039286 | -1.118271 | 1.275147 |
| 3 | Afghanistan | 2005 | 1.843376 | -0.811812 | -0.084575 | -0.039076 | -1.064139 | 1.211189 |
| 4 | Afghanistan | 2006 | 1.816066 | -0.810319 | -0.083448 | -0.035519 | -1.008125 | 1.176293 |
population.set_index('Year', inplace=True)
#population.groupby('Entity')['Natural_growth_rate'].plot(legend=True, figsize=(20, 5))
population.groupby('Entity').plot(legend=True, figsize=(20, 5))
#growth = pd.concat( [ gb.get_group(group) for i,group in enumerate( gb.groups) if i < 5 ] ).groupby('Entity')
#growth.plot(legend=True, figsize=(20, 5))
c:\Users\Shenghao\anaconda3\envs\ANLY501\lib\site-packages\pandas\plotting\_matplotlib\core.py:386: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). fig = self.plt.figure(figsize=self.figsize)
Entity
Afghanistan AxesSubplot(0.125,0.11;0.775x0.77)
Albania AxesSubplot(0.125,0.11;0.775x0.77)
Algeria AxesSubplot(0.125,0.11;0.775x0.77)
Angola AxesSubplot(0.125,0.11;0.775x0.77)
Antigua and Barbuda AxesSubplot(0.125,0.11;0.775x0.77)
...
Vanuatu AxesSubplot(0.125,0.11;0.775x0.77)
Vietnam AxesSubplot(0.125,0.11;0.775x0.77)
World AxesSubplot(0.125,0.11;0.775x0.77)
Zambia AxesSubplot(0.125,0.11;0.775x0.77)
Zimbabwe AxesSubplot(0.125,0.11;0.775x0.77)
Length: 187, dtype: object